package com.kili.picture.controller;

import com.kili.picture.context.Result;
import com.kili.picture.context.ResultStatus;
import com.kili.picture.domain.model.picture.config.PictureConfigCreateDTO;
import com.kili.picture.domain.model.picture.config.PictureConfigDetailDTO;
import com.kili.picture.domain.model.picture.config.PictureConfigUpdateDTO;
import com.kili.picture.service.PictureConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author Jar
 * @Date 2019/4/4
 */
@RestController
@RequestMapping("/picture/config")
public class PictureConfigController {

    @Autowired
    private PictureConfigService pictureConfigService;

    @PostMapping
    public Result<PictureConfigDetailDTO> create(@Valid @RequestBody PictureConfigCreateDTO create) {
        PictureConfigDetailDTO pictureConfigDetailDTO = pictureConfigService.create(create);
        Result<PictureConfigDetailDTO> result = new Result<>();
        result.setResultStatus(ResultStatus.OK);
        result.setData(pictureConfigDetailDTO);
        return result;
    }

    @PutMapping
    public Result<PictureConfigDetailDTO> update(@Valid @RequestBody PictureConfigUpdateDTO update) {
        PictureConfigDetailDTO pictureConfigDetailDTO = pictureConfigService.update(update);
        Result<PictureConfigDetailDTO> result = new Result<>();
        result.setResultStatus(ResultStatus.OK);
        result.setData(pictureConfigDetailDTO);
        return result;
    }

}
